import store from '@/store'

//自定义指令名称
const hasAuth = 'auth';

//鉴权逻辑
const handler = (el, binding) => {
    //传递给指令的值(按钮权限标识符)
    const _code = binding.value;
    //从vuex中获取按钮权限标识符列表
    let btnList = store.state.user.info.buttonList;
    if (btnList) {
        //从权限列表中判断是否存在当前指令按钮的权限标识符
        const flag = btnList.filter(item => {
            return _code === item
        });

        //不存在，删除按钮节点
        if (flag.length === 0) {
            el.parentNode.removeChild(el);
        }
    }
}
export {
    hasAuth,
    handler
}